package com.example.parallelandroid;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.parallelandroid.entity.Setting;

import java.util.ArrayList;
import java.util.List;

public class SettingActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private ListView lvList;
    private List<Setting> lvsettings;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        setting();
        // 为ToolBar添加返回键
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true); // 添加默认的返回图标
        getSupportActionBar().setHomeButtonEnabled(true); // 设置返回键可用
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        lvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                //获取被点击的对象
                Setting item = lvsettings.get(i);
                switch (item.getValue()){
                    case "个人资料":
                        //跳转到另一个activity
                        Intent intent1 = new Intent(SettingActivity.this,PersonalActivity.class);
                        startActivity(intent1);
                        Constant.logger.info("Jump from SettingActivity to PersonalActivity");
                        break;
                    case "账号与安全":
                        //跳转到另一个activity
                        Intent intent2 = new Intent(SettingActivity.this,AccountActivity.class);
                        startActivity(intent2);
                        Constant.logger.info("Jump from SettingActivity to AccountActivity");
                        break;
                    case "提醒服务":
                        //跳转到另一个activity
                        Intent intent3 = new Intent(SettingActivity.this,ClockActivity.class);
                        startActivity(intent3);
                        Constant.logger.info("Jump from SettingActivity to ClockActivity");
                        break;
                }

            }
        });

    }

    private void setting() {
        toolbar = findViewById(R.id.toolbar);
        lvList = (ListView) findViewById(R.id.lv_list);
        lvsettings = setData();
        SettingAdapter adapter = new SettingAdapter(this,lvsettings,R.layout.settinglist_item);
        lvList.setAdapter(adapter);
    }


    private List<Setting> setData() {
        List<Setting> settings = new ArrayList<>();

        Setting st1 = new Setting();
        st1.setImg(R.mipmap.role);
        st1.setValue("个人资料");
        settings.add(st1);
        Setting st2 = new Setting();
        st2.setImg(R.mipmap.edit);
        st2.setValue("账号与安全");
        settings.add(st2);
        Setting st3 = new Setting();
        st3.setImg(R.mipmap.clock);
        st3.setValue("提醒服务");
        settings.add(st3);

        return settings;

    }

    //
    public void buttonClicked(View view) {
        //跳转到主界面
        Intent intent = new Intent(SettingActivity.this,MainFromActivity.class);
        startActivity(intent);
    }
}